package consys.social.nosql.dao.hbase;

import java.io.IOException;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;

/**
 * Inteface for hbase operations
 *
 * @author Petr Kunc
 */
public interface HBase {

    /**
     * saves data in DB (replaces or adds)
     *
     * @param put to be put in db
     * @throws IOException
     */
    void put(final Put put) throws IOException;

    /**
     * loads data from DB
     *
     * @param get to be got from db
     * @return result of get
     * @throws IOException
     */
    Result get(final Get get) throws IOException;

    /**
     * deletes data from DB
     *
     * @param delete to be deleted from db
     * @throws IOException
     */
    void delete(final Delete delete) throws IOException;

    /**
     * deletes data from DB if the first column in param delete is true
     *
     * @param delete to be deleted from db
     * @return true if deleted / false otherwise
     * @throws IOException
     */
    boolean deleteIfTrue(final Delete delete) throws IOException;

    boolean deleteIfGet(final Get get, final Delete delete) throws IOException;

    /**
     * saves data only if it is not in database (it checks only if the first column in put is not in DB)
     *
     * @param put to be put in DB
     * @return true if added / false otherwise
     * @throws IOException
     */
    boolean add(final Put put) throws IOException;

    /**
     * saves data only if it is in database (it checks only if the first column in put is in DB)
     *
     * @param put to be put in DB
     * @return true if replaced / false otherwise
     * @throws IOException
     */
    boolean replace(final Put put) throws IOException;

    /**
     * increment value in database (it should be long)
     *
     * @param row
     * @param family
     * @param col column
     * @param value the increment (can be negative to decrement)
     * @return new value after increment
     * @throws IOException
     */
    long increment(String row, String family, String col, long value) throws IOException;

    /**
     *
     * @param row
     * @param family
     * @param col column
     * @param value the increment (can be negative to decrement)
     * @return new value after increment
     * @throws IOException
     */
    long increment(byte[] row, String family, String col, long value) throws IOException;

    /**
     * Get scanner to go through data
     *
     * @param scan
     * @return scanner
     * @throws IOException
     */
    ResultScanner getScanner(final Scan scan) throws IOException;
    boolean exists(final Get get) throws IOException;
}